package Views;

import Dao.ScoreDao;
import Dao.TwoPara;
import java.util.Scanner;

/**
 * 执行更改学生信息
 * @author 秦亚辉
 *
 */
public class UpdateStuInfoView {
    public void mainView() {
        TwoPara twoPara = new TwoPara();
        ScoreDao scoreDao = new ScoreDao();

        Scanner input = new Scanner(System.in);
        System.out.println("执行更改学生信息");
        System.out.println("****************************************");
        System.out.println("\n\t\t1.更改学生姓名\n");
        System.out.println("\t\t2.更改学生成绩\n");
        System.out.println("****************************************");
        System.out.println("请选择,输入数字或者按0返回上一级菜单：");
        int number = input.nextInt();
        switch (number) {
            case 0:
                StudentView studentView = new StudentView();
                studentView.mainView();
                break;
            case 1:
                String flag1;
                do {
                    System.out.println("请输入原学生姓名：");
                    String stuNamePre = input.next();
                    System.out.println("请输入新学生姓名");
                    String stuNameNew = input.next();
                    twoPara.renameStudent(stuNamePre,stuNameNew);
                    System.out.println("更改成功！ 是否继续，y or n");//没有检测是否成功。。。。反正就是成功。。。
                    flag1 = input.next();

                } while ("y".equals(flag1));
                break;
            case 2:
                String flag2;
                do {
                    System.out.println("请输入学生姓名：");
                    String stuName = input.next();
                    System.out.println("请输入要更改的课程");
                    String courseNameNew = input.next();
                    System.out.println("请输入成绩");
                    int score = input.nextInt();
                    Boolean isOk = scoreDao.changeScore(courseNameNew,stuName,score);
                    if (isOk) {
                        System.out.println("更改成功！ 是否继续，y or n");//没有检测是否成功。。。。反正就是成功。。。
                        flag2 = input.next();
                    }
                    else{
                        flag2 = "y";
                    }
                }
                while ("y".equals(flag2));
                break;
            default:
                System.out.println("请输入正确信息！");
                break;

        }
    }
}
